package leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-30 19:18
 **/
public class LeetCode884 {

    public String[] uncommonFromSentences(String s1, String s2) {
        String[] str1 = s1.split(" ");
        String[] str2 = s2.split(" ");
        Map<String, Integer> map1 = new HashMap<>();
        Map<String, Integer> map2 = new HashMap<>();
        for (String s : str1) {
            map1.put(s, map1.getOrDefault(s, 0) + 1);
        }

        for (String s : str2) {
            map2.put(s, map2.getOrDefault(s, 0) + 1);
        }
        List<String> res = new ArrayList<>();
        for (String s : map1.keySet()) {
            if (map1.get(s) == 1 && !map2.containsKey(s)) {
                res.add(s);
            }
        }

        for (String s : map2.keySet()) {
            if (map2.get(s) == 1 && !map1.containsKey(s)) {
                res.add(s);
            }
        }

        return res.toArray(new String[0]);

    }

}
